import { ElLoading } from 'element-plus'

// 定义一个全局加载计数器和 Loading 实例引用
let needLoadingRequestCount = 0
let loadingInstance

// 显示全屏 Loading
export const showFullScreenLoading = (info:any) => {
  if (needLoadingRequestCount === 0) {
    loadingInstance = ElLoading.service({
      fullscreen: true,
      lock: true,
      text: info.tips,
      background: 'rgba(0, 0, 0, 0.7)'
    })
  }
  needLoadingRequestCount++
}

// 尝试隐藏全屏 Loading
export const tryHideFullScreenLoading = () => {
  if (needLoadingRequestCount <= 0) return
  needLoadingRequestCount--
  if (needLoadingRequestCount === 0) {
    loadingInstance?.close()
  }
}